package com.invengo.module_check.ui.fragment.feature.item;

import static com.invengo.module_check.data.entity.FeatureBean.FIRST_MODULE;
import static com.invengo.module_check.data.entity.FeatureBean.LAYER_MODULE;
import static com.invengo.module_check.data.entity.FeatureBean.PUBLIC_MODULE;

import android.graphics.drawable.Drawable;

import androidx.annotation.NonNull;
import androidx.core.content.ContextCompat;
import androidx.databinding.ObservableBoolean;
import androidx.databinding.ObservableField;

import com.invengo.module_check.data.entity.FeatureBean;
import com.invengo.module_check.ui.fragment.feature.FeatureViewModel;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.ItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.bus.event.SingleLiveEvent;
import me.goldze.mvvmhabit.utils.cache.ACache;
import me.goldze.mvvmhabit.utils.cache.AKey;

/**
 * @author buoker
 * @version 1.0.0
 * @date 2023/10/24
 * @className java.lang.String
 */
public class FeatureItemViewModel extends ItemViewModel<FeatureViewModel> {
    public Drawable drawableImg;
    public ObservableField<FeatureBean> bean = new ObservableField<>();
    private boolean isLayermodule = ACache.getInstance().getAsBoolean(AKey.FEATURE_MODULE);

    public FeatureItemViewModel(@NonNull FeatureViewModel viewModel, FeatureBean featureBean) {
        super(viewModel);
        switch (featureBean.getModel()) {
            case LAYER_MODULE:
                featureBean.setOpen(!isLayermodule);
                break;
            case PUBLIC_MODULE:
                break;
            case FIRST_MODULE:
                featureBean.setOpen(isLayermodule);
                break;
        }
        bean.set(featureBean);
        drawableImg = ContextCompat.getDrawable(viewModel.getApplication(), featureBean.getActionArgs().getIcon());
    }

    public void changeModule(boolean ischeck) {
        bean.get().setOpen(ischeck);
    }
}
